﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace canyinguanlixitong
{
    public partial class frmhuiyuan : Form
    {
        public frmhuiyuan()
        {
            InitializeComponent();
        }

        private void label9_Click(object sender, EventArgs e)
        {

        }
        string str = "Data Source=.;Initial Catalog=Supermarket management system;User ID=sa;Password=123456";
        private void button1_Click(object sender, EventArgs e)
        {
            add();

        }
        DataSet ds = new DataSet("Student");
        SqlDataAdapter asd;
        //查询
        public void add() {
            SqlConnection conn = new SqlConnection(str);
            try
            {
                string qw1 = this.txtname1.Text;
                string sql = @"select  vipID,vipLeiName,vipName,vipSex,vipMorey,vipDip,vipQi from dbo.VIPtype,dbo.VIPuser
where dbo.VIPtype.vipLeiHao=dbo.VIPuser.vipLei  and vipLeiHao Like'%" +qw1+"%' ";
                 asd = new SqlDataAdapter(sql, conn);
                if (ds.Tables["Student"] != null)
                {
                    ds.Tables["Student"].Clear();
                }
                asd.Fill(ds, "Student");
                dataGridView1.DataSource = ds.Tables["Student"];
              

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void button5_Click(object sender, EventArgs e)
        {
            frmqw1xinzeng frm = new frmqw1xinzeng();
            frm.ShowDialog();
            add();
        }
        //删除
        private void button10_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count > 0)
            {
                DialogResult name = MessageBox.Show("确定删除吗", "提示", MessageBoxButtons.OKCancel,MessageBoxIcon.Question);
                if (name == DialogResult.OK)
                {
                    int stuno = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["huiyuanbianhao"].Value);

                    SqlConnection conn = new SqlConnection(str);
                    try
                    {

                        conn.Open();
                        string sql = "delete dbo.VIPuser where vipID='" + stuno + "'";
                        SqlCommand comm = new SqlCommand(sql, conn);
                        int i = comm.ExecuteNonQuery();
                        if (i > 0)
                        {
                            MessageBox.Show("删除成功");
                            add();
                        }
                        else
                        {
                            MessageBox.Show("删除失败");
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    finally
                    {
                        conn.Close();
                    }
                }

            }
            else {
                MessageBox.Show("选择一行", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            }

        }
      

        private void button13_Click(object sender, EventArgs e)
        {
            cha();
        }
      //查

        public void cha() {
            SqlConnection conn = new SqlConnection(str);
            DataSet ds = new DataSet("Student");
            string sql = @"select vipLeiName,vipID,vipMorey,vipName,vipPwd,vipQi from dbo.VIPtype,dbo.VIPuser
where dbo.VIPtype.vipLeiHao=dbo.VIPuser.vipLei and vipID like'%" + this.txtnamestu.Text + "%' ";
            asd = new SqlDataAdapter(sql,conn);
            if(ds.Tables["Student"]!=null){
                ds.Tables["Student"].Clear();
            }
            asd.Fill(ds,"Student");
            dataGridView2.DataSource = ds.Tables["Student"];
        
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string sql = string.Empty;
            SqlConnection conn = new SqlConnection(str);
            DataSet ds = new DataSet("Student");
            sql = "select userID,userName,userSex, userDian,userQi,userBorn from dbo.UserTpye where userName like'%"+this.txtbianhao.Text.Trim()+"%'";
           
            SqlDataAdapter asdf = new SqlDataAdapter(sql,conn);
            asdf.Fill(ds,"Student");
            dataGridView4.DataSource = ds.Tables["Student"];

        }

      
        private void 查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
        add();
        }

        private void 增加ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmqw1xinzeng frm = new frmqw1xinzeng();
            frm.Show();
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        //修改
        private void button11_Click(object sender, EventArgs e)
        {

            if (this.dataGridView1.SelectedRows.Count > 0)
            {
                frmqw1xiugai frm = new frmqw1xiugai();
                frm.stu = Convert.ToInt32(this.dataGridView1.SelectedCells[0].Value.ToString());
                frm.ShowDialog();
                add();  

            }
            else
            {
                MessageBox.Show("选择一行", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            }
           
        }

        private void frmhuiyuan_Load(object sender, EventArgs e)
        {
            add();
        }

        private void txtname1_TextChanged(object sender, EventArgs e)
        {
            add();
        }

        private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
        {

        }

     

       


      
       

    }
}
